<?php
/**
 * Abstract.php
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@mygem.org so we can send you a copy immediately.
 *
 * @copyright   Copyright (c) 2012, MyGem <info@mygem.org>
 * @package     MyGem\Db
 */


abstract class MyGem_Db_Abstract extends MyGem_Base
{

    protected $connection = null;
    protected $hostname = 'localhost';
    protected $username = 'root';
    protected $password = '';
    protected $dbname = '';
    protected $params = array();
    protected $errors = array();

    public function __construct($hostname, $username, $password, $dbname, $params = array())
    {
        $this->hostname = $hostname;
        $this->username = $username;
        $this->password = $password;
        $this->dbname = $dbname;
        $this->params = $params;
    }

    abstract protected function _connect();

    abstract public function escape($value);

    abstract public function select($sql);

    abstract public function selectSingle($sql);

    abstract public function query($sql);

    abstract public function lastInsertId();

    public function connect()
    {
        return $this->_connect();
    }

    public function quote($value, $escape = true)
    {
        if ($escape) $value = $this->escape($value);
        return "'{$value}'";
    }

}
